package com.ahora.org.controller.biometrico.servlet;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ahora.org.controller.util.Estatica;
import com.ahora.org.ejb.jpa.beans.UsuarioBiometrico;

/**
 * Servlet implementation class BiometricoServlet
 */
@WebServlet("/ServletEstadoIdentificacion")
public class BiometricoServletEstadoIdentificacion extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private UsuarioBiometrico processSomething(HttpServletRequest request) {
		UsuarioBiometrico myrespObj = null;
		UsuarioBiometrico myObject = null;
		try {
			ObjectInputStream inputFromApplet = new ObjectInputStream(
					request.getInputStream());
			myObject = (UsuarioBiometrico) inputFromApplet.readObject();
	
			Estatica.inicializarUsuarioEstado();
			Estatica.setUsuarioEstado(myObject);

			myrespObj = new UsuarioBiometrico();
			myrespObj.setNombre("Ronny Isac Morales Sanchez");
			myrespObj.setApellido("Morales");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return myrespObj;
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			UsuarioBiometrico myrespObj = processSomething(request);
			response.reset();
			response.setHeader("Content-Type", "application/x-java-serialized-object");
			ObjectOutputStream outputToApplet;
			outputToApplet = new ObjectOutputStream(response.getOutputStream());
			outputToApplet.writeObject(myrespObj);
			outputToApplet.flush();
			outputToApplet.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
